package com.yanjr.modules.sys.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.yanjr.common.Constants;
import com.yanjr.common.persistence.BaseDaoImpl;
import com.yanjr.modules.sys.dao.OfficeDao;
import com.yanjr.modules.sys.entity.Office;

@Repository("officeDao")
public class OfficeDaoImpl extends BaseDaoImpl<Office> implements OfficeDao {

	@Override
	public List<Office> findByParentIdsLike(String parentIds) {
		String sql = "select * from sys_office where del_flag=? and parent_ids like ?";
		return super.findList(sql, new Object[] {Constants.DEL_FLAG_NORMAL, parentIds});
	}

	@Override
	public List<Office> findAllChild(String parentId, String likeParentIds) {
		String sql = "select * from sys_office where (id=? or parent_id=? or parent_ids like ?) and del_flag=? order by code";
		return super.findList(sql, new Object[] {parentId, parentId, likeParentIds, Constants.DEL_FLAG_NORMAL});
	}

	@Override
	public List<Office> findByRoleId(String roleId) {
		String sql = "select * from sys_office o join sys_role_office ro on o.id=ro.office_id where o.del_flag=? and ro.role_id=?";
		return super.findList(sql, new Object[] {Constants.DEL_FLAG_NORMAL, roleId});
	}

}
